﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TeachingAffairsManagementSystem.WebControl;

namespace TeachingAffairsManagementSystem
{
    public partial class ChangePassWord : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // 判断登录状态
            if ((bool) Session["isLoggedIn"] == false || Session["userType"].ToString() == "admin")
            {
                // 未登录 跳回主页
                Response.Redirect("~/Home.aspx");
            }
        }

        protected void BtnChange_Click(object sender, EventArgs e)
        {
            int id = Convert.ToInt32(Session["id"]);
            string newPassword = TBNewPassword.Text;
            if (newPassword == "")
            {
                Alert.Show("密码不能为空", AlertBox.Level.Danger, true);
                return;
            }

            switch (Session["userType"])
            {
                case "student":
                    if (Operation.UpdateStudentPassword(id, newPassword))
                    {
                        Alert.Show("修改成功", AlertBox.Level.Success, true);
                    }

                    break;
                case "teacher":
                    if (Operation.UpdateTeacherPassword(id, newPassword))
                    {
                        Alert.Show("修改成功", AlertBox.Level.Success, true);
                    }

                    break;
            }
        }
    }
}